<?php 
function pr($arrs,$exit = 1){
    echo '<pre>';
    print_r($arrs);
    echo '</pre>';
    if($exit){
        exit;
    }
}
class Person {
    
    public function __construct($name= ''){
        if($name){
            $this->name = $name;
            
        }
    }
    
    /**
     * for the sake of demonstration, we are setting this private
     **/
    private $_allowAttr = false;
    /**
     * type=primary autoincrement
     */
    protected $id = 0;
    
    /**
     * type=varchar length=255 null
     */
    protected $name;
    
    /**
     * type=text null
     */
    protected $biography;
    
    public function getId(){
        return $this->id;
    }
    
    public function setId($id){
        $this->id = $id;   
    }
    public function getName() {
        return $this->name;
    }
    public function setName($v) {
        $this->name = $v;
    }
    public function getBiography() {
        return $this->biography;
    }
    public function setBiography($v) {
        $this->biography = $v;
    }
}
//****************************ReflectionClass********************************
    $class = new ReflectionClass('Person');//建立Person这个类的反射类
    $instance = $class->newInstanceArgs(['WDV']); //$args 相当于实例化Person 类 

    //获取properties
    $properties = $class->getProperties();
    foreach ($properties as $property) {
//         echo $property->getName() . "<br/>";//获取属性名称

        //获取注释信息
//            if($property->isProtected()){
//                $docblock = $property->getDocComment();;
//                preg_match('/ type\=([a-z_]*) /', $property->getDocComment(), $matches);
//                echo $matches[1];
//            }
    }
    //获取所有方法
    pr($class->getMethods(),0);
    //是否存在某个方法
    pr($class->hasMethod('setId'),0);
    //获取某个方法
    pr($class->getMethod('setId'),0);
    
    //执行类中的方法
    echo $instance->getName(); // 执行Person 里的方法getName
    
//****************************ReflectionMethod********************************
    $method = new ReflectionMethod('Person','setId');
    if ($method->isPublic() && !$method->isStatic()) {
        echo 'Action is right';
    }
    echo $method->getNumberOfParameters(); // 参数个数
    echo $method->getParameters(); // 参数对象数组
    pr($method);


?>